package com.zhangwei.day41photo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.zhangwei.day41photo.R;
import com.zhangwei.day41photo.bean.UpdateInfo;

import java.util.List;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.zhangwei.day41photo.adapter
 * @Description:
 * @date 15/10/22 下午2:53
 */


public class UPdateImageAdapter extends BaseAdapter {

    private Context context;
    private List<UpdateInfo> infos;


    public UPdateImageAdapter(Context context, List<UpdateInfo> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return infos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_update_layout, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        if (infos.get(position).isCheck()){
            vh.checkBox.setChecked(true);
        }else {
            vh.checkBox.setChecked(false);
        }
        vh.img.setImageBitmap(infos.get(position).getBitmap());
        return convertView;
    }

    public static class ViewHolder

    {
        public ImageView img;
        public CheckBox checkBox;

        public ViewHolder(View view) {
            img = (ImageView) view.findViewById(R.id.update_item_img);
            checkBox = (CheckBox) view.findViewById(R.id.update_item_checkbox);
        }

        public ImageView getImg() {
            return img;
        }

        public void setImg(ImageView img) {
            this.img = img;
        }

        public CheckBox getCheckBox() {
            return checkBox;
        }

        public void setCheckBox(CheckBox checkBox) {
            this.checkBox = checkBox;
        }
    }


}
